﻿using CommHelper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SHDServer
{
    public sealed class GlobalData
    {
        /// <summary>
        /// 最大连接数
        /// </summary>
        public static int NumConnections = AppSettingsHelper.GetInt("NumConnections");

        /// <summary>
        /// 开放的端口
        /// </summary>
        public static int ListenPort = AppSettingsHelper.GetInt("ListenPort");

        /// <summary>
        /// 接受数据缓存大小
        /// </summary>
        public static int ReceiveBufferSize = AppSettingsHelper.GetInt("ReceiveBufferSize");

        /// <summary>
        /// 商家ID
        /// </summary>
        public static string sid = AppSettingsHelper.GetText("shop_id").Trim();

        /// <summary>
        /// 预定义的云平台URL
        /// </summary>
        public static string mainUrl = AppSettingsHelper.GetText("mainUrl").Trim();

        private static int _ScanCodeOrderSpeechInterval = AppSettingsHelper.GetInt("ScanCodeOrderSpeechInterval");

        /// <summary>
        /// 新的扫码订单提示间隔时间
        /// </summary>
        public static int ScanCodeOrderSpeechInterval
        {
            get
            {
                if (_ScanCodeOrderSpeechInterval < 10 || _ScanCodeOrderSpeechInterval > 120)
                    _ScanCodeOrderSpeechInterval = 30;
                return _ScanCodeOrderSpeechInterval;
            }
        }

        private static string _ScanCodeOrderSpeechText = AppSettingsHelper.GetText("ScanCodeOrderSpeechText");

        /// <summary>
        /// 新的扫码订单提示间隔时间
        /// </summary>
        public static string ScanCodeOrderSpeechText
        {
            get
            {
                if (string.IsNullOrEmpty(_ScanCodeOrderSpeechText))
                    _ScanCodeOrderSpeechText = "你有新的扫码订单";
                return _ScanCodeOrderSpeechText;
            }
        }

        private static List<long> _ScanCodeOrders = new List<long>();
        private static readonly object ScanCodeOrdersObj = new object();

        /// <summary>
        /// 未完成的扫描订单
        /// </summary>
        public static List<long> ScanCodeOrders
        {
            get
            {
                if (_ScanCodeOrders == null) _ScanCodeOrders = new List<long>();
                return _ScanCodeOrders;
            }
            set
            {
                lock (ScanCodeOrdersObj)
                    _ScanCodeOrders = value;
            }
        }
    }
}